#define  _CRT_SECURE_NO_WARNINGS 1

#include <stdio.h>

struct ListNode
{
    int val;
    int next;
};

struct ListNode* getIntersectionNode(struct ListNode* headA, struct ListNode* headB) {
    struct ListNode* curA = headA;
    struct ListNode* curB = headB;
    int lenA = 1;
    int lenB = 1;

    while (curA->next)
    {
        curA = curA->next;
        lenA++;
    }

    while (curB->next)
    {
        curB = curB->next;
        lenB++;
    }

    if (curA != curB)
    {
        return NULL;
    }

    curA = headA;
    curB = headB;
    struct ListNode* longList = curA;
    struct ListNode* shortList = curB;

    if (lenA < lenB)
    {
        longList = curB;
        shortList = curA;
    }

    int k = abs(lenA - lenB);

    while (k--)
    {
        longList = longList->next;
    }

    while (longList != shortList)
    {
        longList = longList->next;
        shortList = shortList->next;
    }

    struct ListNode* Node = longList;

    return Node;

}

int main()
{


	return 0;
}